package maxProfit121;

public class MaxProfit {

    //左侧最小值与右侧最大值差
    public int maxProfit(int[] prices) {

        int low = Integer.MAX_VALUE;
        int result = 0;
        for (int i = 0; i < prices.length; i++) {
            if(low > prices[i]){
                low = prices[i];
            }else{
                if(prices[i] - low > result){
                    result = prices[i] - low;

                }
            }

        }

        return result;
    }

}
